package com.fire.controller;

import com.fire.api.AppService;
import com.fire.api.dto.AppDTO;
import com.fire.common.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author fire
 * @date 2021年07月18日12:53
 */
@Api(value = "商户平台--应用管理",tags = "商户平台-应用相关",description ="商户平台-应用相关" )
@RestController
public class AppController {
    @DubboReference
    private AppService appService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "app",value = "应用信息",required = true,dataType = "AppDto",paramType = "body")
    })
    @PostMapping("/my/apps")
    public AppDTO createApp(@RequestBody AppDTO app){
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.createApp(merchantId,app);
    }

    @ApiOperation("查询商户下的应用列表")
    @GetMapping("/my/apps")
    public List<AppDTO> queryByApps(){
//        从token中获取
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.queryAppByMerchantId(merchantId);
    }

    @ApiOperation("根据App_id获得应用的详细信息")
    @ApiImplicitParam(name = "appId",value = "商户应用ID",required = true,dataType = "String",paramType = "path")
    @GetMapping("/my/apps/{appId}")
    public AppDTO getApp(@PathVariable("appId") String appId){
            return appService.getAppByAppId(appId);
    }
}
